package
{
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import tooltip_pkg.Tooltip;
	 
public class TControl 
{
	public var DebugParent: TControl = null;
	public static var ToolTip: Tooltip = null;
	public static var InDrag: Boolean = false;
	
	public var Tag: int = -1;
	public var Ctrl: DisplayObjectContainer;
	private var fHint: String = "";
	public function get Hint(): String
	{
		return fHint;
	}
	
	public function set Hint(s: String): void
	{
		fHint = s;
		if (fHint != "")
		{
			Ctrl.addEventListener(MouseEvent.MOUSE_MOVE, ShowToolTip);		
			Ctrl.addEventListener(MouseEvent.MOUSE_OUT, RemoveToolTip);					
		}
	}
	
	private var fEnabled: Boolean = true;
	public function get Enabled(): Boolean
	{
       return fEnabled;
	}

   public function set Enabled( v : Boolean ): void
   {
	   fEnabled = v;
       return;
   }		
	
	public function get X(): Number
	{
       return Ctrl.x;
	}

   public function set X( v : Number ): void
   {
	   Ctrl.x = v;
       return;
   }
   
	public function get Y():Number
	{
       return Ctrl.y;
	}

   public function set Y( v : Number ):void
   {
	   Ctrl.y = v;
       return;
   }   
   
	public function get Width():Number
	{
       return Ctrl.width;
	}

   public function set Width( v : Number ):void
   {
	   Ctrl.width = v;
       return;
   }   
   
	public function get Height():Number
	{
       return Ctrl.height;
	}

   public function set Height( v : Number ):void
   {
	   Ctrl.height = v;
       return;	   
   }      
   
	public function get Visible():Boolean
	{
	   return Ctrl.visible;
	}

   public function set Visible( v : Boolean ):void
   {
	   Ctrl.visible = v;
       return;	   
   }
   
   private function StopDrag(): void
   {
	   if (Ctrl is Sprite)
		(Ctrl as Sprite).stopDrag();
   }
   
   private function TryStopDrag(e: MouseEvent): void
   {
		if (!InDrag)
			return;
		if (!(e.buttonDown))
			StopDrag();
   }
   
    public function addEventListener (type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false) : void
	{
		Ctrl.addEventListener (type, listener, useCapture, priority, useWeakReference);
	}
	
	public function AddChild(aCtrl: TControl): void
	{
		Ctrl.addChild(aCtrl.Ctrl);
	}
	
	private function ShowToolTip(e:MouseEvent): void
	{
		//new TModalMessage(Hint);
		if (!(ToolTip.Visible))
			ToolTip.showTip(Hint, X, Y);
	}
	
	private function RemoveToolTip(e:MouseEvent): void
	{
		ToolTip.removeTip();
	}
   	
	public function TControl(aCtrl: MovieClip, Parent: TControl = null, x: Number = 0, y: Number = 0)
	{	
	    if (DebugParent == null)
		  DebugParent = Parent;
		if (ToolTip == null)
		  if (DebugParent != null)
            ToolTip = new Tooltip(0xFFFF00, 0x22BB22, DebugParent.Ctrl);

		Ctrl = aCtrl;
		Ctrl.x = x;
		Ctrl.y = y;	
		if (Parent != null)
			Parent.Ctrl.addChild(Ctrl);
			
		Ctrl.addEventListener(MouseEvent.MOUSE_MOVE, TryStopDrag);		

	}		
}	
}